package bio.mytomcat;

import java.io.IOException;
import java.io.OutputStream;

/**
 * @Author LuZhouJin
 * @Date 2023/8/4
 * 自定义的Response 基于HTTP协议
 */
public class MyResponse {

    private OutputStream out;

    public MyResponse(OutputStream out) {
        this.out = out;
    }

    public void write(String data) throws IOException {
        //遵循HTTP规则输出数据
        //状态码 200
        StringBuilder sb = new StringBuilder();
        sb.append("HTTP/1.1 200 OK\n")
                .append("Content-Type: text/html;\n")
                .append("\r\n")
                .append(data);
        out.write(sb.toString().getBytes());
    }
}
